<?php
namespace app\admin\controller;

use app\admin\middleware\Auth;
use app\admin\middleware\AuthToken;

/**
 * Class User
 * @package app\admin\logic
 * @property \app\admin\logic\User logicUser
 */
class User extends ControllerBase
{
    /**
     * @OA\Post(
     *   tags={"用户"},
     *   path="/user/login",
     *   summary="登录接口",
     *   @OA\Parameter(name="username", in="query", @OA\Schema(type="string"), required=true, description="用户姓名"),
     *   @OA\Parameter(name="password", in="query", @OA\Schema(type="string"), required=true, description="用户密码"),
     *   @OA\Response(
     *     response=200,
     *     description=""
     *   )
     * )
     */
    public function login()
    {
        return result()->data($this->logicUser->login(request()->param()))->toJson();
    }

    /**
     * @OA\Get(
     *   tags={"用户"},
     *   path="/user/current",
     *   summary="获取当前登录用户的信息",
     *   @OA\Response(
     *     response=200,
     *     description="返回当前登录用户信息"
     *   )
     * )
     */
    public function current(){
        return result()->data($this->logicUser->current(Auth::$user))->toJson();
    }

    /**
     * @OA\Delete   (
     *   tags={"用户"},
     *   path="/user/logout",
     *   summary="退出登录",
     *   @OA\Response(
     *     @OA\MediaType( mediaType="application/json"),
     *     response=200,
     *     description=""
     *   )
     * )
     */
    public function logout(){
        return result()->data($this->logicUser->logout(Auth::$user))->toJson();
    }

    /**
     * @OA\Get(
     *   tags={"用户"},
     *   path="/user/getList",
     *   summary="获取用户列表",
     *   @OA\Response(
     *     @OA\MediaType( mediaType="application/json"),
     *     response=200,
     *     description="返回用户列表"
     *   )
     * )
     */
    public function getList(){
        return result()->data($this->logicUser->getList(request()->param()))->toJson();
    }

    /**
     * @OA\Post(
     *   tags={"用户"},
     *   path="/user/add",
     *   summary="新增用户信息",
     *   @OA\Response(
     *     @OA\MediaType( mediaType="application/json"),
     *     response=200,
     *     description=""
     *   )
     * )
     */
    public function add(){
        return result()->data($this->logicUser->add(request()->param()))->toJson();
    }

    /**
     * @OA\Patch(
     *   tags={"用户"},
     *   path="/user/update",
     *   summary="更新用户信息",
     *   @OA\Response(
     *     @OA\MediaType( mediaType="application/json"),
     *     response=200,
     *     description=""
     *   )
     * )
     */
    public function update(){
        return result()->data($this->logicUser->update(request()->param()))->toJson();
    }

    /**
     * @OA\Patch(
     *   tags={"用户"},
     *   path="/user/editPassword",
     *   summary="修改密码",
     *   @OA\Response(
     *     @OA\MediaType( mediaType="application/json"),
     *     response=200,
     *     description=""
     *   )
     * )
     */
    public function editPassword(){
        return result()->data($this->logicUser->editPassword(request()->param()))->toJson();
    }

    /**
     * @OA\Delete (
     *   tags={"用户"},
     *   path="/user/del",
     *   summary="删除用户信息",
     *   @OA\Response(
     *     @OA\MediaType( mediaType="application/json"),
     *     response=200,
     *     description=""
     *   )
     * )
     */
    public function del(){
        return result()->data($this->logicUser->del(request()->param()))->toJson();
    }
}
